From 77ec53b686ec6e16df4df5095aef2db90b737b91 Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Wed, 5 Aug 2009 14:02:46 +0100 Subject: [PATCH] x86 vmx: Accelerate VLAPIC EOI writes Our testing indicates that most apic accesses are eoi writes. This patch accelerate guest EOI emulation utilizing HW VM Exit information. Without this patch, xentrace shows the apci access average tsc costs is ~7.8k in our case and it down to ~3k with it. We also save 3% cpu in our case. From: Yang Zhang Signed-off-by: Keir Fraser --- xen/arch/x86/hvm/vmx/vmx.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index df8cccba52..477f2e26b2 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -2270,6 +2270,26 @@ static void vmx_vmexit_ud_intercept(struct cpu_user_regs *regs) } } +static int vmx_handle_eoi_write(void) +{ + unsigned long exit_qualification = __vmread(EXIT_QUALIFICATION); + + /* + * 1. Must be a linear access data write. + * 2. Data write must be to the EOI register. + */ + if ( (((exit_qualification >> 12) & 0xf) == 1) && + ((exit_qualification & 0xfff) == APIC_EOI) ) + { + int inst_len = __get_instruction_length(); /* Safe: APIC data write */ + __update_guest_eip(inst_len); + vlapic_EOI_set(vcpu_vlapic(current)); + return 1; + } + + return 0; +} + asmlinkage void vmx_vmexit_handler(struct cpu_user_regs *regs) { unsigned int exit_reason, idtv_info; @@ -2572,8 +2592,12 @@ asmlinkage void vmx_vmexit_handler(struct cpu_user_regs *regs) case EXIT_REASON_TPR_BELOW_THRESHOLD: break; - case EXIT_REASON_IO_INSTRUCTION: case EXIT_REASON_APIC_ACCESS: + if ( !vmx_handle_eoi_write() && !handle_mmio() ) + vmx_inject_hw_exception(TRAP_gp_fault, 0); + break; + + case EXIT_REASON_IO_INSTRUCTION: if ( !handle_mmio() ) vmx_inject_hw_exception(TRAP_gp_fault, 0); break; -- 2.30.2